# 1、确定文件存储账号信息的结构
accounts = {
    #'xxx':["a","b","r"]
}
f = open("account.db", "r")

for line in f:
    line = line.strip().split(",")
    accounts[line[0]] = line
print(accounts)
# 2、搞个loop(循环)，让用户输入账号密码 进行判断

while True:
    user = input("输入用户名：").strip()
    if user not in accounts:
        print("请输入正确的用户名！")
        continue
    if accounts[user][2] == "1":
        print("账号被锁定了！")
        continue
    count = 0
    while count < 3:
        pwd = input("输入密码：").strip()
        if pwd == accounts[user][1]:
            print(f"Welcome {user} ...登录成功...")
            # break
            exit("bye....")
        else:
            print("密码输入错误请重新输入")
        count += 1
    if count == 3:  # 输入错误三次 锁定系统
        print(f"输错了{count}密码，{user}账号锁定")
        # 1.先改内存中的账号信息，用户状态
        # 2.把dict里的数据转成原account.db数据格式，并且存回文件
        accounts[user][2] = "1"
        f2 = open("account.db", mode="w")
        for user, value in accounts.items():
            line = ",".join(value) + "\n"  # 列表转换为字符串
            f2.write(line)
        f2.close()
        exit("bye.")